import { create, deleteByPrimaryKey, listAllByPage, update } from '@/services/electronicscaleApi';

export default {
  namespace: 'electronicscale',

  state: {
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *listAllByPage({ payload }, { call, put }) {
      const response = yield call(listAllByPage, payload);

      yield put({
        type: 'cb4listAllByPage',
        payload: response,
      });
    },

    *create({ payload }, { call, put }) {
      const response = yield call(create, payload);
      return response;
    },

    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      return response;
    },

    *deleteByPrimaryKey({ payload }, { call, put }) {
      const response = yield call(deleteByPrimaryKey, payload);
      return response;
    },
  },

  reducers: {
    cb4listAllByPage(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
